package it.getta.vicinometro.utils;

import it.getta.vicinometro.model.LocationInfo;
import it.getta.vicinometro.tracking.TrackingTask;

import com.google.android.maps.GeoPoint;

import android.content.Intent;

public class IntentParser {

	public static LocationInfo parseIntent(Intent intent) {
		double longitudeE6 = intent.getDoubleExtra(TrackingTask.EXTRA_CONTENT_LONGITUDE, -1) * 1e6;
	    double latitudeE6 = intent.getDoubleExtra(TrackingTask.EXTRA_CONTENT_LATITUDE, -1) * 1e6; 
	    float speed = intent.getFloatExtra(TrackingTask.EXTRA_CONTENT_SPEED, 0); 
	    double altitude = intent.getDoubleExtra(TrackingTask.EXTRA_CONTENT_ALTITUDE, -1);
	    long timestamp = intent.getLongExtra(TrackingTask.EXTRA_CONTENT_TIMESTAMP, -1);
	    long timeToFirstFix = intent.getLongExtra(TrackingTask.EXTRA_CONTENT_TIME_TO_FIRST_FIX, -1);
	    
	    //speed
	    speed *= 100;
	    speed = (float)Math.round(speed)/100;
	    
	    //geo point
	    int longitude = (int) longitudeE6;
	    int latitude = (int) latitudeE6;
	    GeoPoint point = new GeoPoint(latitude, longitude);
	    
	    LocationInfo li = new LocationInfo();
	    li.setGeoPoint(point);
	    li.setSpeed(speed);
	    li.setTimeToFirstFix(timeToFirstFix);
	    li.setAltitude(altitude);
	    li.setTimeStamp(timestamp);
	    
	    return li;
	}
	
	
}
